//////////////////////////////////////////////////////////////////////////////////
//	 Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#ifndef _IP_TO_COUNTRY_
#define _IP_TO_COUNTRY_

// N/A flag/country has zero index
#define NO_COUNTRY_INFO		0

#include "def.h"

class CIP2Country
{
public:
								CIP2Country(void);
								~CIP2Country(void);

	void						Load();
	
	wxImageList*				GetFlagImageList()	{return m_pCountryFlagImage;}
	int							GetFlag(unsigned long lIP);

	wxString					GetCountry( unsigned long lIP );



private:
	void						BuidImageList();
	unsigned short				StringToCode(const char* strCode);
	size_t						GetIdx(unsigned long lIP, size_t nFrom, size_t nTo );

private:
	wxImageList*				m_pCountryFlagImage;

	typedef std::map<unsigned short, int> COUNTRYTOIMAGE;
	COUNTRYTOIMAGE				m_mpCountryToImageID;

	typedef struct tagIPINFO
	{
		unsigned long  lFrom;
		unsigned long  lTo;
		unsigned short wCountry;
		std::string	   strCountryShort;
		std::string	   strCountryFull;
	}IPINFO;

	typedef std::vector<IPINFO>	IPCOUNTRYLIST;
	IPCOUNTRYLIST				m_lstIPRange;


	typedef struct tagIPCACHEINFO
	{
		int			   nImageID;
		wxString	   strCountryFull;
	}IPCACHEINFO;

	IPCACHEINFO					LookUp(unsigned long lIP);

	typedef std::map<unsigned long, IPCACHEINFO> IPCACHE;
	IPCACHE						m_mpIPCache;
};

#endif // _IP_TO_COUNTRY_